package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Softwit;
import com.zygh.policeasset.service.SoftwitService;
import com.zygh.policeasset.service.UploadFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/Softwit"})
@Api(tags = {"智能软件资产"}, description = "SoftwitController")
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/SoftwitController.class */
public class SoftwitController {
    @Autowired
    SoftwitService softwitService;
    @Autowired
    private UploadFileService uploadFileService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加智能软件资产")
    public Object add(@RequestBody Softwit softwit) {
        if (StringUtil.isEmpty(softwit.getBuildNum())) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        if (this.softwitService.insert(softwit) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除智能软件资产")
    public Object delete(Integer id) {
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("智能软件资产主键不能为空");
        }
        if (this.softwitService.deleteById(id.intValue()) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改智能软件资产")
    public Object update(@RequestBody Softwit softwit) {
        if (StringUtil.isEmpty(String.valueOf(softwit.getId()))) {
            return new CommonResult().validateFailed("智能软件资产主键不能为空");
        }
        if (this.softwitService.updateById(softwit) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/selectbyid"}, method = {RequestMethod.GET})
    @ApiOperation("单条智能软件资产")
    public Object selectById(@RequestParam Integer id) {
        if (StringUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("智能软件资产主键不能为空");
        }
        return new CommonResult().success(this.softwitService.findById(id));
    }

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("查询全部智能软件资产")
    public Object findAll() {
        return new CommonResult().success(this.softwitService.findAll());
    }

    @RequestMapping(value = {"/findbycondition"}, method = {RequestMethod.GET})
    @ApiOperation("按项目编号查询")
    public Object findByCondition(@RequestParam String buildNum, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        if (StringUtil.isEmpty(buildNum)) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        return this.softwitService.findByCondition(buildNum, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findByroleid"}, method = {RequestMethod.GET})
    @ApiOperation("按角色、编号、资产状态查询")
    public Object findByRoleId(Softwit softwit, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.softwitService.findByRoleId(softwit, pageNum, pageSize);
    }

    @RequestMapping(value = {"/updassetsClassificationId"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "ids", value = "资产主键集合，逗号隔开", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationId", value = "资产新分类Id", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationPid", value = "资产新分类父Id", required = true, paramType = "query")})
    @ApiOperation("修改资产分类编号")
    public Object updassetsClassificationId(@RequestBody JSONObject json) {
        if (this.softwitService.updassetsClassificationId(json.getString("ids"), json.getInteger("assetsClassificationId"), json.getInteger("assetsClassificationPid")).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }
}